package com.sw.chinesewriteboard.activity;

import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sw.chinesewriteboard.R;
import com.sw.chinesewriteboard.config.ChineseDataConfig;
import com.sw.chinesewriteboard.copybook.ZhCopybookActivity;
import com.sw.chinesewriteboard.model.ChineseData;
import com.sw.chinesewriteboard.operation.ChineseDataOperate;

/**
 * @Description: 汉字字帖
 * @author: GordenGao
 * @Email: gordengao124@gmail.com
 * @date: 2021年06月21日 9:26
 */
public class ZhPin2WordCopybookActivity extends ZhCopybookActivity {

    @Override
    protected void initOwnView() {
//        setTitle("看汉字写拼音字帖");
        ChineseDataConfig.setRow(11);
        binding.vbnBottomNavigation.initEnvironment(this, true);
        binding.vbnBottomNavigation.setContantHint("请输入生成字帖的汉字。例如：英文字帖");
        binding.vbnBottomNavigation.findViewById(R.id.vbn_gezi_csl_kongbaihang).setVisibility(View.GONE);
        binding.vbnBottomNavigation.findViewById(R.id.vbn_ziti_ll_alpha).setVisibility(View.GONE);
        binding.vbnBottomNavigation.findViewById(R.id.vbn_gezi_csl_miao).setVisibility(View.GONE);
    }

    @Override
    protected boolean isPinyinEnabled() {
        return true;
    }

    @Override
    protected boolean needInitDir() {
        return false;
    }

    @Override
    protected ChineseDataOperate.ArrangeType setArrangeType() {
        return ChineseDataOperate.ArrangeType.PIN2WORD;
    }

    protected View createCharacterLayout(char c, ChineseData data) {
        int gridWidth = ChineseDataConfig.getGridWidth(ZhPin2WordCopybookActivity.this);

        LinearLayout characterLayout = new LinearLayout(this);
        characterLayout.setLayoutParams(new LinearLayout.LayoutParams(WRC, WRC));
        characterLayout.setOrientation(LinearLayout.VERTICAL);

        final TextView character = new TextView(this);

        if (isPinyinEnabled()) {
            final TextView pinyin = new TextView(this);
            pinyin.setGravity(Gravity.CENTER);
            pinyin.setEnabled(true);

            characterLayout.addView(pinyin, new LinearLayout.LayoutParams(gridWidth, gridWidth * 4 / 7));

            mCharacterOperation.set3LinesAppearance(pinyin, data);
            mEditTextList.add(pinyin);
        }


        character.setGravity(Gravity.CENTER);
        LinearLayout.LayoutParams characterParams = new LinearLayout.LayoutParams(gridWidth, gridWidth);
        characterParams.bottomMargin = 30;
        character.setEnabled(false);
        character.setText("" + c);
        mCharacterOperation.setCharacterAppearance(character, data);
        mEditTextList.add(character);
        characterLayout.addView(character, characterParams);

        return characterLayout;
    }
}
